import 'package:flutter/material.dart';
import '../utils/general.dart';
import '../components/ffrow.dart';
import '../utils/icon.dart';
import '../pages/login.dart';
class Mine extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return MineState();
  }

}

class MineState extends State<Mine> {

  int number = 0;

    Widget getUserPortrait() {
    if (FFShareInstance.info.portrait.length > 0) {
      return Image.network(FFShareInstance.info.portrait, width: 66, height: 66, fit:BoxFit.fill);
    }else {
      return Image.asset('assets/images/logo1.png',);
    }
  }


  // 顶部用户登录信息
  Widget topWidget(BuildContext context) {
    double scale = widthScale(context);
    return Stack(
      children:<Widget>[
        Container(
          height: 180 * scale,
          color: Color.fromRGBO(104, 68, 60, 1.0),
          child: Center(
            child:GestureDetector(
              onTap:(){
                Navigator.of(context).push(PageRouteBuilder(pageBuilder: (context, ani, ani2){
                  return Login();
                }, fullscreenDialog: true));
              },
              child:Row(
                mainAxisAlignment:MainAxisAlignment.spaceBetween,
                children:[
                  Row(
                    children:[
                      Padding(
                        padding: EdgeInsets.fromLTRB(16.0, 0, 10.0, 0),
                        child: Align(
                          child:ClipOval(
                            child:SizedBox(
                              width:66,
                              height:66,
                              child:getUserPortrait(),
                            ),
                          ),
                        ),
                      ),
                      Text(FFShareInstance.info.nickname.length > 0 ? FFShareInstance.info.nickname : '立即登录', style: TextStyle(fontSize:18, fontWeight:FontWeight.bold, color:Colors.white),),                      
                    ]
                  ),
                  SizedBox(
                    width:24,
                    height:14,
                    child:Padding(
                      padding: EdgeInsets.only(right: 10.0),
                      child:Icon(Icons.arrow_forward_ios, color: Colors.white,)
                    ),
                  )
                ]
              )
            )
          ),
        )
      ]
    );
  }
  
  // 右侧组件 文字信息 + 箭头
  Widget listCellRightWidget({String info}) {
    if (info == null) {
      return Icon(Icons.arrow_forward_ios, size:14, color:Color.fromRGBO(232, 228, 228, 1.0));
    }else {
      return Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Padding(
            padding: EdgeInsets.only(right:6),
            child: Text(
              info,
              style:TextStyle(fontSize: 14, fontWeight:FontWeight.bold, color:Color.fromRGBO(166, 166, 166, 1.0)),
            ),
          ),
          Icon(Icons.arrow_forward_ios, size:14, color:Color.fromRGBO(232, 228, 228, 1.0)),
        ],
      );
    }
  }

  // 获取展示的组件
  Widget acquireRightWidget(String e) {
    if (e == '咖啡钱包' && number > 0) {
      return listCellRightWidget(info:'$number杯');
    }else {
      return listCellRightWidget();
    }
  }

  // 用户列表信息
  List<Widget> listCell(BuildContext context) {

    double scale = widthScale(context);

    List<Widget> list = [];

    list.add(topWidget(context));

    List<Widget> temp = ['个人资料', '咖啡钱包', '优惠券', '兑换优惠', '发票管理', '帮助反馈'].map((e){
      if (e == '帮助反馈') {
        return Padding(
          padding: EdgeInsets.only(top: 10 * scale),
          child: FFRow(
            leading:iconshoucang(size:22, color:Color.fromRGBO(224, 220, 220, 1.0)),
            subtitle: e,
            trailing: acquireRightWidget(e),
            padding: EdgeInsets.fromLTRB(16.0, 16.0 * scale, 16.0, 16.0 * scale),
            textStyle: TextStyle(fontSize:14.0, color:Color.fromRGBO(56, 56, 56, 1.0), fontWeight: FontWeight.bold),
            onpress: (){
              print(e);
              setState(() {
                number += 1;
              });
            },
          ),
        );
      }else {
        return FFRow(
          leading:icontupian12(size:22, color:Color.fromRGBO(224, 220, 220, 1.0)),
          subtitle: e,
          trailing: acquireRightWidget(e),
          padding: EdgeInsets.fromLTRB(16.0, 16.0 * scale, 16.0, 16.0 * scale),
          textStyle: TextStyle(fontSize:14.0, color:Color.fromRGBO(56, 56, 56, 1.0), fontWeight: FontWeight.bold),
          onpress: (){
            print(e);
          },
        );
      }
    }).toList();
    list.addAll(temp);

    list.add(
      Padding(
        padding: EdgeInsets.symmetric(horizontal:16.0),
        child:Image.asset('assets/images/mine/mine2.jpg', fit:BoxFit.fill),
      )
    );
    return list;
  }
  

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child:Container(
        color: separatorLineColor,
        height: screenHeight(context) - 88,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children:listCell(context),
        ),
      )
    );
  }

}
